package com.juyu.reader.pc.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	public static String formatDate(Date date) {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateString = dateFormater.format(date);
		return dateString;
	}

	public static Date pareDate(String dateString) {
		try {
			SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = dateFormater.parse(dateString);
			return date;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Date pareDateShort(String dateString) {
		try {
			SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
			Date date = dateFormater.parse(dateString);
			return date;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String getDayBegin(Date date) {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormater.format(date);
		dateString = dateString + " 00:00:00";

		return dateString;
	}

	public static String getDayEnd(Date date) {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormater.format(date);
		dateString = dateString + " 23:59:59";
		return dateString;
	}

	public static String getDayBeginByMonth() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.DAY_OF_MONTH, 1);
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormater.format(cal.getTime());
		return dateString;
	}

	public static String getDayEndByMonth() {
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.add(Calendar.DAY_OF_MONTH, 1);
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormater.format(cal.getTime());
		return dateString;
	}

	public static String getShortDate(Date date) {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		String dateString = dateFormater.format(date);
		return dateString;
	}

	public static String getStartDate(Date date) {
		SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
		String dateString = dateFormater.format(date);
		return dateString;
	}
}
